<template>
  <div class="toast">{{message}}</div>
</template>

<script>
import {reactive,toRefs} from "vue";

export default {
  name: "Toast",
  props: ['message']
};

export const useToastEffect = () => {
  const toastData = reactive({
    toastVisible: false,
    toastMessage: ''
  })

  const showToast = (message) => {
    toastData.toastVisible = true
    toastData.toastMessage = message
    setTimeout(() => {
      toastData.toastVisible = false;
      toastData.toastMessage = ''
    }, 2000);
  }

  const {toastVisible,toastMessage} = toRefs(toastData);
  return {toastVisible, toastMessage, showToast}
};

</script>

<style lang="scss" scoped>
@import '../style/variables';
.toast{
  position: fixed;
  left:50%;
  top:50%;
  transform: translate(-50%,-50%);
  padding: .1rem;
  background: rgba(0,0,0,.35);
  border-radius: .05rem;
  color: $bgColor;
}
</style>
